package homework14;

public class Work3_Thread extends Thread {
    private static int n = 100;

    @Override
    public void run() {
        for(;;){
            synchronized (Work3_Thread.class) {
                if(n <= 0) {
                    System.out.println("票已售罄！");
                    break;
                } else {
                    System.out.println(Thread.currentThread().getName() +" 卖掉第" + (101-n) + "张票，剩余" + (n-1) + "张票！");
                    n--;
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
